package com.jinmdz.fmis.api.api.service;

import com.jinmdz.fmis.api.base.BaseService;
import com.jinmdz.fmis.api.model.config.ConfigData;
import com.jinmdz.fmis.api.model.config.dictionary.ColdStorageStatusCode;
import com.jinmdz.fmis.api.model.config.dictionary.DictionaryCode;
import com.jinmdz.fmis.api.model.config.dictionary.HallStatusCode;
import com.jinmdz.fmis.api.wrapper.DictionaryWrapper;
import com.jinmdz.fmis.api.wrapper.DocumentWrapper;
import com.jinmdz.fmis.api.wrapper.ResponseWrapper;
import com.jinmdz.fmis.common.ext.ArrayListExt;
import com.jinmdz.fmis.common.ext.StringBuilderExt;
import com.jinmdz.fmis.common.model.PoiTable;
import com.jinmdz.fmis.common.util.DataUtil;
import com.jinmdz.fmis.common.util.DateUtil;
import com.jinmdz.fmis.common.util.third.PoiUtil;
import com.jinmdz.fmis.common.wrapper.PoiWrapper;
import com.jinmdz.fmis.core.base.BaseBean;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.core.constant.Constants;
import com.jinmdz.fmis.core.constant.EDictCode;
import com.jinmdz.fmis.core.exception.ActionException;
import com.jinmdz.fmis.core.model.SearchListData;
import com.jinmdz.fmis.core.model.SearchLoadData;
import com.jinmdz.fmis.dao.dao.SearchDao;
import com.jinmdz.fmis.dao.dao.SearchOverviewDao;
import com.jinmdz.fmis.dao.model.dictionary.DataDictionaryItem;
import com.jinmdz.fmis.dao.model.search.*;
import com.jinmdz.fmis.dao.model.search.businessoverview.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

/**
 * 殡葬业务查询
 *
 * @author GuanKui
 * @date 2020/2/24 14:31
 */
@Service("searchService")
public class SearchService extends BaseService {

    @Resource
    private SearchDao searchDao;

    @Resource
    private DictionaryWrapper dictionaryWrapper;

    @Resource
    private ResponseWrapper responseWrapper;

    @Resource
    private DictionaryCode dictionaryCode;

    @Resource
    private SearchOverviewDao searchOverviewDao;

    @Resource
    private HallStatusCode hallStatusCode;

    @Resource
    private ColdStorageStatusCode coldStorageStatusCode;

    @Resource
    private ConfigData configData;

    @Resource
    private DocumentWrapper documentWrapper;

    /**
     * 火化档案（逝者）信息查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/24  14:28
     */
    public BaseResult<SearchLoadData<SearchCremationArchivesViewItem>> loadCremationArchives(SearchCremationArchivesData data) {
        // 初始化分页数据
        startPageData(data);
        // 火化档案（逝者）信息查询
        ArrayList<SearchCremationArchivesViewItem> loadItems = loadCremationArchivesViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchCremationArchivesViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 火化档案（逝者）信息导出Excel
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/24  14:28
     */
    public void loadCremationArchivesExportExcel(SearchCremationArchivesData data) {
        ArrayList<SearchCremationArchivesViewItem> loadItems = loadCremationArchivesViewItems(data);
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchCremationArchivesViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 获取火化档案（逝者）列表
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/26  15:45
     */
    private ArrayList<SearchCremationArchivesViewItem> loadCremationArchivesViewItems(SearchCremationArchivesData data) {
        // 火化档案（逝者）信息查询
        ArrayList<SearchCremationArchivesViewItem> loadItems = searchDao.listCremationArchives(data);
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);
        // 处理查询数据
        loadItems.forEach(loadItem -> {
            if (DataUtil.valid(loadItem.getAgentUnit())) {
                StringBuilderExt builder = new StringBuilderExt();
                builder.format("{0} {1}", loadItem.getAgentUnit(), loadItem.getAgentName());
                loadItem.setAgentName(builder.toString());
            }

        });
        return loadItems;
    }

    /**
     * 冷藏业务查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/24  17:03
     */
    public BaseResult<SearchLoadData<SearchColdStorageViewItem>> loadColdStorage(SearchColdStorageData data) {
        // 初始化分页数据
        startPageData(data);
        ArrayList<SearchColdStorageViewItem> loadItems = loadColdStorageViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchColdStorageViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 获取冷藏业务列表
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/24  17:03
     */
    private ArrayList<SearchColdStorageViewItem> loadColdStorageViewItems(SearchColdStorageData data) {
        // 冷藏业务查询
        ArrayList<SearchColdStorageViewItem> loadItems = searchDao.listColdStorage(data);
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);
        return loadItems;
    }

    /**
     * 冷藏业务查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/24  17:03
     */
    public void loadColdStorageExportExcel(SearchColdStorageData data) {
        // 冷藏业务查询
        ArrayList<SearchColdStorageViewItem> loadItems = loadColdStorageViewItems(data);
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchColdStorageViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 礼厅业务查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/24  17:37
     */
    public BaseResult<SearchLoadData<SearchMournCeremonyViewItem>> loadMournCeremony(SearchMournCeremonyData data) {
        // 初始化分页数据
        startPageData(data);
        // 礼厅业务查询
        ArrayList<SearchMournCeremonyViewItem> loadItems = loadMournCeremonyViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchMournCeremonyViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 礼厅业务查询导出Excel
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/24  17:37
     */
    public void loadMournCeremonyExportExcel(SearchMournCeremonyData data) {
        ArrayList<SearchMournCeremonyViewItem> loadItems = loadMournCeremonyViewItems(data);
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchMournCeremonyViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 礼厅业务查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/27  10:44
     */
    private ArrayList<SearchMournCeremonyViewItem> loadMournCeremonyViewItems(SearchMournCeremonyData data) {
        // 礼厅业务查询
        ArrayList<SearchMournCeremonyViewItem> loadItems = searchDao.listMournCeremony(data);

        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);

        loadItems.forEach(loadItem -> {
            String businessType = loadItem.getBusinessType();
            if (DataUtil.valid(loadItem.getBusinessType())) {
                if (Constants.WAKE_MOURN_TYPE.equals(businessType)) {
                    loadItem.setBusinessType("守灵");
                } else if (Constants.FAREWELL_MOURN_TYPE.equals(businessType)) {
                    loadItem.setBusinessType("告别");
                }
            }
        });
        return loadItems;
    }

    /**
     * 火化数据查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/25  14:38
     */
    public BaseResult<SearchLoadData<SearchCremationDataViewItem>> loadCremationData(SearchCremationData data) {
        // 初始化分页数据
        startPageData(data);
        // 火化数据查询
        ArrayList<SearchCremationDataViewItem> loadItems = loadCremationDataViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchCremationDataViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 火化数据查询导出Excel
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/25  14:38
     */
    public void loadCremationDataExportExcel(SearchCremationData data) throws ActionException {
        ArrayList<SearchCremationDataViewItem> loadItems = loadCremationDataViewItems(data);
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchCremationDataViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 火化数据查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/27  10:57
     */
    private ArrayList<SearchCremationDataViewItem> loadCremationDataViewItems(SearchCremationData data) {
        // 火化数据查询
        ArrayList<SearchCremationDataViewItem> loadItems = searchDao.listCremationData(data);
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);

        loadItems.forEach(loadItem -> {
            loadItem.setAsAppointmentText(DataUtil.valid(loadItem.getAsAppointment()) ? "是" : "否");
        });

        return loadItems;
    }

    /**
     * 火化台账查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/25  14:38
     */
    public BaseResult<SearchLoadData<SearchCremationLedgerViewItem>> loadCremationLedger(SearchCremationLedgerData data) {
        // 初始化分页数据
        startPageData(data);
        // 火化台账查询
        ArrayList<SearchCremationLedgerViewItem> loadItems = loadCremationLedgerViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchCremationLedgerViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 火化台账查询导出Excel
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/25  14:38
     */
    public void loadCremationLedgerExportExcel(SearchCremationLedgerData data) {
        ArrayList<SearchCremationLedgerViewItem> loadItems = loadCremationLedgerViewItems(data);
        /*导出excel*/
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchCremationLedgerViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 火化台账查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/27  11:11
     */
    private ArrayList<SearchCremationLedgerViewItem> loadCremationLedgerViewItems(SearchCremationLedgerData data) {
        // 火化台账查询
        ArrayList<SearchCremationLedgerViewItem> loadItems = searchDao.listCremationLedger(data, dictionaryCode.getCremationTypeYiTi());
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);

        loadItems.forEach(loadItem -> {
            loadItem.setAsLocalText(DataUtil.valid(loadItem.getAsLocal()) ? "是" : "否");
            loadItem.setAsAppointmentText(DataUtil.valid(loadItem.getAsAppointment()) ? "是" : "否");
            StringBuilderExt builder = new StringBuilderExt();
            builder.format("{0} {1}", loadItem.getMobilePhone(), loadItem.getOtherPhone());
            loadItem.setPhone(builder.toString());
        });
        return loadItems;
    }

    /**
     * 费用查询
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/26  9:57
     */
    public BaseResult<SearchLoadData<SearchChargeViewItem>> loadChargeQuery(SearchChargeData data) {
        // 初始化分页数据
        startPageData(data);
        // 费用查询
        ArrayList<SearchChargeViewItem> loadItems = loadChargeQueryViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchChargeViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 费用查询导出Excel
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/26  9:57
     */
    public void loadChargeQueryExportExcel(SearchChargeData data) {
        // 费用查询
        ArrayList<SearchChargeViewItem> loadItems = loadChargeQueryViewItems(data);
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchChargeViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 费用信息查询
     *
     * @param data 查询实体
     * @return
     * @author LiCongLu
     * @date 2020-03-07 12:03
     */
    private ArrayList<SearchChargeViewItem> loadChargeQueryViewItems(SearchChargeData data) {
        // 费用查询
        ArrayList<SearchChargeViewItem> loadItems = searchDao.listChargeQuery(data, dictionaryCode.getInvoiceStateZuoFei());
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);

        loadItems.forEach(loadItem -> {
            loadItem.setAsSettledText(DataUtil.valid(loadItem.getAsSettled()) ? "已结算" : "未结算");
        });
        return loadItems;
    }

    /**
     * 惠民减免统计
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/26  13:26
     */
    public BaseResult<SearchLoadData<SearchHuiMinViewItem>> loadHuiMinReduction(SearchHuiMinData data) {
        // 初始化分页数据
        startPageData(data);
        // 惠民减免统计
        ArrayList<SearchHuiMinViewItem> loadItems = loadHuiMinViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchHuiMinViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 惠民减免统计导出Excel
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/26  13:26
     */
    public void loadHuiMinReductionExportExcel(SearchHuiMinData data) {
        // 惠民减免统计
        ArrayList<SearchHuiMinViewItem> loadItems = loadHuiMinViewItems(data);
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchHuiMinViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 惠民减免统计
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/27  11:42
     */
    private ArrayList<SearchHuiMinViewItem> loadHuiMinViewItems(SearchHuiMinData data) {
        // 惠民减免统计
        ArrayList<SearchHuiMinViewItem> loadItems = searchDao.listHuiMinReduction(data);
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);
        return loadItems;
    }

    /**
     * 殡仪馆收入统计
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/26  14:44
     */
    public BaseResult<SearchListData> loadRevenueStatistics(SearchRevenueStatisticsData data) {
        // 初始化分页数据
        startPageData(data);
        // 殡仪馆收入统计
        ArrayList<SearchRevenueStatisticsViewItem> loadItems = searchDao.listRevenueStatistics(data, dictionaryCode.getInvoiceStateZuoFei());

        // 初始化返回实体
        SearchLoadData<SearchRevenueStatisticsViewItem> loadData = getSearchLoadData(loadItems);

        // 获取类型
        ArrayList<DataDictionaryItem> typeList = dictionaryWrapper.listDataDictionaryItem(EDictCode.PAY_TYPE);

        // 返回动态数据集合
        SearchListData listData = new SearchListData();
        listData.setHeader(getRevenueStatisticsHeader(typeList))
                .setList(getRevenueStatisticsList(typeList, loadData.getList()))
                .setPager(loadData.getPager());
        return successData(listData);
    }

    /**
     * 获取表格列名
     *
     * @param typeList 付款类型结合
     * @return
     * @author LiCongLu
     * @date 2020-03-07 17:38
     */
    private ArrayList<String> getRevenueStatisticsHeader(ArrayList<DataDictionaryItem> typeList) {
        ArrayListExt<String> headerList = new ArrayListExt<>();
        headerList.addExt("业务编码", "逝者姓名", "家属姓名", "应收金额", "优惠金额", "惠民金额"
                , "结算金额");
        // 追加付款方式
        typeList.forEach(payType -> {
            headerList.addExt(payType.getDataText());
        });

        headerList.addExt("合计", "结算项目编号", "结算时间", "结算项目", "发票号", "收据号");
        return headerList;
    }

    /**
     * 殡仪馆收入统计导出excel
     *
     * @param data 查询实体
     * @return
     * @author GuanKui
     * @date 2020/2/26  14:44
     */
    public void loadRevenueStatisticsExportExcel(SearchRevenueStatisticsData data) {
        // 殡仪馆收入统计
        ArrayList<SearchRevenueStatisticsViewItem> loadItems = searchDao.listRevenueStatistics(data, dictionaryCode.getInvoiceStateZuoFei());
        // 获取类型
        ArrayList<DataDictionaryItem> typeList = dictionaryWrapper.listDataDictionaryItem(EDictCode.PAY_TYPE);

        // 得到列名
        ArrayList<String> header = getRevenueStatisticsHeader(typeList);
        // 得到行数
        ArrayList<ArrayList<String>> list = getRevenueStatisticsList(typeList, loadItems);

        // 表标题
        String title = "殡仪馆收入统计";
        PoiTable poiTable = PoiWrapper.createPoiTable(title, title, header, list);
        exportExcelFile(poiTable);
    }

    /**
     * 殡仪馆收入统计
     *
     * @param typeList  付款类型集合
     * @param loadItems 加载实体
     * @return
     * @author GuanKui
     * @date 2020/2/27  13:09
     */
    private ArrayList<ArrayList<String>> getRevenueStatisticsList(ArrayList<DataDictionaryItem> typeList, List<SearchRevenueStatisticsViewItem> loadItems) {
        ArrayList<ArrayList<String>> list = new ArrayList<>();
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);
        // 得到结算集合
        ArrayList<Integer> chargeSettleIds = new ArrayList<>();
        loadItems.forEach(loadItem -> {
            chargeSettleIds.add(loadItem.getId());
        });

        // 判断是否有结算主键
        if (DataUtil.valid(chargeSettleIds)) {
            // 获取所有付款信息集合
            ArrayList<SearchRevenueStatisticsPayItem> payItems = searchDao.listRevenueStatisticsPayByChargeSettleIds(chargeSettleIds);
            // 遍历记载数据，生成最后数据集合
            loadItems.forEach(loadItem -> {
                ArrayListExt<String> rowList = new ArrayListExt<>();
                rowList.addExt(loadItem.getBusinessCode(), loadItem.getDeadName(), loadItem.getMemberName())
                        .addExt(DataUtil.getPlainString(loadItem.getReceiptCharge()))
                        .addExt(DataUtil.getPlainString(loadItem.getDiscountCharge()))
                        .addExt(DataUtil.getPlainString(loadItem.getBenefitCharge()))
                        .addExt(DataUtil.getPlainString(loadItem.getSettleCharge()));
                BigDecimal payTotalCharge = new BigDecimal(0);

                // 遍历付款类型
                for (DataDictionaryItem payType : typeList) {
                    String payValue = "";
                    // 迭代遍历付款统计
                    Iterator<SearchRevenueStatisticsPayItem> iterator = payItems.iterator();
                    while (iterator.hasNext()) {
                        SearchRevenueStatisticsPayItem payItem = iterator.next();
                        // 得到种类付款总额
                        if (DataUtil.equals(loadItem.getId(), payItem.getChargeSettleId())
                                && DataUtil.equals(payType.getDataCode(), payItem.getPayTypeCode())) {
                            payTotalCharge = payTotalCharge.add(payItem.getPayCharge());
                            payValue = DataUtil.getPlainString(payItem.getPayCharge());
                            iterator.remove();
                            break;
                        }
                    }
                    rowList.addExt(payValue);
                }

                rowList.addExt(DataUtil.getPlainString(payTotalCharge))
                        .addExt(loadItem.getSettleBatchNo())
                        .addExt(DateUtil.formatPattern(loadItem.getSettleTime(), BaseBean.yyyy_MM_dd_HH_mm))
                        .addExt(loadItem.getSettleType(), loadItem.getInvoiceNo(), loadItem.getReceiptNo());
                list.add(rowList);
            });
        }

        return list;
    }

    /**
     * 殡仪馆数据总览
     *
     * @param
     * @return
     * @author GuanKui
     * @date 2020/2/27  8:53
     */
    public BaseResult<BusinessOverviewItem> loadBusinessOverview() {
        // 当前日期
        Date nowDate = nowDate();

        // 统计设定天数每天馆逝者个数
        int beforeDays = configData.getBusinessOverviewArrivedDays();
        String currentDay = DateUtil.formatPattern10(nowDate);
        Date beforeDate = DateUtil.getBeforeDay(nowDate, beforeDays);
        // 按照提前日期查询统计到馆数量信息
        ArrayList<OverviewArrivedCountItem> arrivedCountItems = searchOverviewDao.listOverviewArrivedCountByArrivedDate(beforeDate);
        // 重新排序以便验证追加空数据
        HashMap<String, OverviewArrivedCountItem> arrivedMap = new HashMap<>(16);
        for (OverviewArrivedCountItem countItem : arrivedCountItems) {
            arrivedMap.put(countItem.getArrivedDate(), countItem);
        }
        // 清空查询结果
        arrivedCountItems.clear();
        // 排序追加空数据
        for (int i = 0; i < beforeDays; i++) {
            // 查询日期
            String arrivedDate = DateUtil.getBeforeDay(currentDay, i, DateUtil.PATTERN_10);
            OverviewArrivedCountItem arrivedCountItem =
                    arrivedMap.containsKey(arrivedDate) ? arrivedMap.get(arrivedDate) : new OverviewArrivedCountItem(arrivedDate, 0);
            // 处理日期，去掉年份
            arrivedCountItem.setArrivedDate(arrivedDate.substring(5));
            arrivedCountItems.add(arrivedCountItem);
        }
        // 数组反向排序
        Collections.reverse(arrivedCountItems);

        // 统计冷柜冷藏情况
        OverviewEquipmentCountItem equipmentCountItem = searchOverviewDao.getOverviewEquipmentCount(coldStorageStatusCode.getYiChuCang());
        if (equipmentCountItem != null) {
            // 重新计划空闲可用冷柜数量
            equipmentCountItem.setEmptyEquipmentCount(equipmentCountItem.getEquipmentCount()
                    - equipmentCountItem.getDisableEquipmentCount()
                    - equipmentCountItem.getInEquipmentCount());
        }

        // 统计礼厅占用情况
        OverviewHallCountItem hallCountItem = searchOverviewDao.getOverviewHallCount(hallStatusCode.getYiChuTing(), hallStatusCode.getYiRuTing());

        // 统计火化炉预约信息
        ArrayList<OverviewFurnaceCountItem> furnaceAllCountItems = searchOverviewDao.listOverviewFurnaceCountByAppointmentDate(nowDate);

        // 获取火化类型主键
        ArrayList<DataDictionaryItem> furnaceTypeItems = dictionaryWrapper.listDataDictionaryItem(EDictCode.FURNACE_TYPE);

        // 火化类型版本
        ArrayList<OverviewFurnaceCountItem> furnaceCountItems = new ArrayListExt<>();
        for (DataDictionaryItem typeItem : furnaceTypeItems) {
            OverviewFurnaceCountItem furnaceCountItem = new OverviewFurnaceCountItem();
            furnaceCountItem.setFurnaceType(typeItem.getDataText())
                    .setFurnaceTypeCode(typeItem.getDataCode());
            for (OverviewFurnaceCountItem overviewFurnaceCountItem : furnaceAllCountItems) {
                if (DataUtil.equals(typeItem.getDataCode(), overviewFurnaceCountItem.getFurnaceTypeCode())) {
                    furnaceCountItem.setAppointmentCount(overviewFurnaceCountItem.getAppointmentCount());
                    break;
                }
            }
            furnaceCountItems.add(furnaceCountItem);
        }

        BusinessOverviewItem loadItem = new BusinessOverviewItem();
        loadItem.setArrivedCounts(arrivedCountItems)
                .setEquipmentCount(equipmentCountItem)
                .setHallCount(hallCountItem)
                .setFurnaceCounts(furnaceCountItems);

        return successData(loadItem);
    }

    /**
     * 导出excel
     *
     * @param poiTable Table
     * @return
     * @author GuanKui
     * @date 2020/2/25  10:45
     */
    private void exportExcelFile(PoiTable poiTable) {
        XSSFWorkbook workbook = PoiUtil.createXSSFWorkbook(poiTable);
        String filename = DateUtil.formatPattern(nowDate(), "yyyy_MM_dd_HH_mm_ss");
        responseWrapper.downloadXlsx(getResponse(), workbook, filename);
    }

    /**
     * 系统操作日志查询
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-04-20 15:25
     */
    public BaseResult<SearchLoadData<SearchOperationLogViewItem>> loadSystemOperationLog(SearchOperationLogData data) {
        // 初始化分页数据
        startPageData(data);
        // 操作日志数据查询
        ArrayList<SearchOperationLogViewItem> loadItems = loadSystemOperationLogViewItems(data);
        // 初始化返回实体
        SearchLoadData<SearchOperationLogViewItem> loadData = getSearchLoadData(loadItems);
        return successData(loadData);
    }

    /**
     * 系统操作日志查询导出Excel
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-04-20 15:26
     */
    public void loadSystemOperationLogExportExcel(SearchOperationLogData data) {
        ArrayList<SearchOperationLogViewItem> loadItems = loadSystemOperationLogViewItems(data);
        PoiTable poiTable = PoiWrapper.createPoiTable(SearchOperationLogViewItem.class, loadItems);
        exportExcelFile(poiTable);
    }

    /**
     * 系统操作日志查询查询
     *
     * @param data 查询实体
     * @return
     * @author LiCongLu
     * @date 2020-04-20 15:26
     */
    private ArrayList<SearchOperationLogViewItem> loadSystemOperationLogViewItems(SearchOperationLogData data) {
        // 操作日志数据查询
        ArrayList<SearchOperationLogViewItem> loadItems = searchDao.listSystemOperationLog(data);
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);
        return loadItems;
    }
}